/**
 *博尔信基础开发平台
 *<br> 版权声明：厦门博尔信软件有限公司版权所有,违者必究
 *<br> Copyright:  Copyright (c) 2012
 *<br> Company:pearlsoft
 *<br> @author 蒋勇华
 *<br> 2012-5-10
 *<br> @version 1.0
 *————————————————————————————————————
 *修改记录
 *    修改者：
 *    修改时间：
 *    修改原因：
 *——————————————————————————————————————
 */
package com.pearlsoft.webapp.rms.resapply;

import java.util.List;
import java.util.Map;

import com.pearlsoft.webapp.core.annotation.QueryHandlerComponent;
import com.pearlsoft.webapp.core.dataset.DataSet;
import com.pearlsoft.webapp.core.dataset.Query;
import com.pearlsoft.webapp.core.dataset.Record;
import com.pearlsoft.webapp.core.web.basehandler.AbsBaseQueryHandler;
import com.pearlsoft.webapp.core.web.session.SessionProfile;
import com.pearlsoft.webapp.core.web.util.HttpUtil;
import com.pearlsoft.webapp.rms.resapply.service.ResApplyService;

/**
 *描述： 
 *
 * 
 */
@QueryHandlerComponent(name = "ResApplyQueryHandler")
public class ResApplyQueryHandler extends AbsBaseQueryHandler{


	@Override
	public void handler(Query query, DataSet ds) throws Exception {
		
	}

	
	public void queryGrid(Query query, DataSet ds) throws Exception {
		String userId = HttpUtil.getCookieValueByName(this.getHttpServletRequest(), SessionProfile.COOKIE_USERID);
		ResApplyService resApplyService = this.getBean("resApplyService", ResApplyService.class);
		List<Record> list = resApplyService.getApplyList(userId);
		ds.setRecords(list);
	}
	
	public void queryInfo(Query query, DataSet ds) throws Exception {
		String startDate = (String) query.get("startDate");
		String endDate = (String) query.get("endDate");
		ResApplyService resApplyService = this.getBean("resApplyService", ResApplyService.class);
		List<Map<String,Object>> list = resApplyService.getRuntimeResource(startDate, endDate);	
		for(Map<String,Object> record:list) {
			ds.newRecord();
			ds.setValue("date", record.get("date"));
			ds.setValue("cpu", record.get("cpu"));
			ds.setValue("mem", record.get("mem"));
			ds.setValue("disk", record.get("disk"));
		}
	}
	
	/***
	 * 审批日志查询
	 * @param query
	 * @param ds
	 * @throws Exception
	 */
	public void queryAudtiLogGrid(Query query, DataSet ds) throws Exception {
		String applyId =(String) query.get("applyId");
		ResApplyService resApplyService = this.getBean("resApplyService", ResApplyService.class);
		List<Record> list = resApplyService.getAuditLogList(applyId);
		ds.setRecords(list);
	}
	
	@Override
	public void getEntity(Query query, DataSet ds) throws Exception {
		String objId =(String) query.get("objId");
		ResApplyService resApplyService = this.getBean("resApplyService", ResApplyService.class);
		Record record=resApplyService.getById(objId);
		ds.addRecrod(record);
	}


	@Override
	public void quickSearch(Query query, DataSet ds) throws Exception {
		
	}


	@Override
	public void advSearch(Query query, DataSet ds) throws Exception {
		// TODO Auto-generated method stub
		
	}

}
